#include<iostream>
#include<string>
#include<map>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e3 + 10;
map<char, PII>mp;
map<char, int>st;
map<char, PII>st2;
struct node
{
	int t, id;
	char c;
	string ans;
}s[N];
int n, t, m;
int main()
{
	cin >> n >> t >> m;
	for (int i = 0; i < m; i++) {
		int t, id;
		char c;
		string ans;
		cin >> t >> id;
		cin >> c;
		cin >> ans;
		s[i] = { t,id,c,ans };
	}
	for (int i = 0; i < m; i++) {
		if (s[i].ans == "Yes") {
			if (st2[s[i].c].first) {
				continue;
			}
			st2[s[i].c] = { s[i].t,s[i].id };
		}
	}
	for (int i = m - 1; i >= 0; i--) {
		if (s[i].ans == "Yes") {
			if (st2[s[i].c].first == s[i].t && st2[s[i].id].second == s[i].id) {
				mp[s[i].c] = { s[i].t,s[i].id };
				st[s[i].c] = 1;
			}	
		}
	}
	for (int i = 0; i < n; i++) {
		char s = 'A' + i;
		cout << s << " ";
		if (st[s]) {
			cout << mp[s].first << " " << mp[s].second << endl;
		}
		else {
			cout << "- -" << endl;
		}
	}
	return 0;
}